import type { BaseEnum } from "@/enums/base";

/**
 * 签到签退类型枚举
 * 用于标识签到和签退操作
 */
export const SignType = {
  /**
   * 签到
   */
  SignOn: {
    code: "SignOn",
    name: "签到",
    index: 1,
    description: "用户签到操作"
  },

  /**
   * 签退
   */
  SignExit: {
    code: "SignExit",
    name: "签退",
    index: 2,
    description: "用户签退操作"
  },
} as const;

/**
 * 根据code获取枚举
 * @param code
 * @returns 枚举值或null
 */
export function matchCode(code: string) {
  return (
    Object.values(SignType).find((item) => item.code === code) || null
  );
}

/**
 * 根据index获取枚举
 * @param index
 * @returns 枚举值或null
 */
export function matchIndex(index: number) {
  return (
    Object.values(SignType).find((item) => item.index === index) || null
  );
}

/**
 * 获取所有签到类型选项
 * @returns 签到类型数组
 */
export function getSignTypeOptions() {
  return Object.values(SignType);
}

/**
 * 判断是否为签到操作
 * @param signType 签到类型枚举值
 * @returns boolean
 */
export function isSignOn(signType: typeof SignType[keyof typeof SignType]): boolean {
  return signType.code === SignType.SignOn.code;
}

/**
 * 判断是否为签退操作
 * @param signType 签到类型枚举值
 * @returns boolean
 */
export function isSignExit(signType: typeof SignType[keyof typeof SignType]): boolean {
  return signType.code === SignType.SignExit.code;
}

/**
 * 获取签到类型的颜色类型（用于UI展示）
 * @param signType 签到类型枚举值
 * @returns Element Plus 的 tag 类型
 */
export function getSignTypeColor(signType: typeof SignType[keyof typeof SignType]): 'success' | 'warning' {
  switch (signType.code) {
    case SignType.SignOn.code:
      return 'success';
    case SignType.SignExit.code:
      return 'warning';
    default:
      return 'success';
  }
} 